
<?php
//Ten file muon xuat ra de in
/*$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
//print_r($arr_single_record);
if(isset($_REQUEST['hdn_recordtype_filter'])){
	$v_recordtype_filter = $_REQUEST['hdn_recordtype_filter'];
} */

if(sizeof($v_record_id_list) <=1){
	$v_recordtype_filter = $arr_single_record['FK_RECORDTYPE'];
	$v_file_name = "giay_bien_nhan.htm";
	$v_xml_str = $arr_single_record['C_RECEIVED_RECORD_XML_DATA'];
	//echo 'v_recordtype_filter'.$v_recordtype_filter; exit;
	//file chua cac the can thay the
	$v_receipt_richtext_file = "../../template/".$v_recordtype_filter."/mau_giay_bien_nhan.htm";
	//echo htmlspecialchars($v_receipt_richtext_file);
	if (!file_exists($v_receipt_richtext_file)){
		$v_receipt_richtext_file = "../../template/mau_giay_bien_nhan.htm";	
	}
	$v_receipt_xml_file = "../../xml/".$v_recordtype_filter."/mau_in_giay_bien_nhan.xml";	
	if (file_exists($v_receipt_xml_file)){
		$v_receipt_xml_string = _read_file($v_receipt_xml_file);
	}else{
		$v_receipt_xml_file = "../../xml/other/mau_in_giay_bien_nhan.xml";
	$v_receipt_xml_string = _read_file($v_receipt_xml_file);
	}
	//echo $v_recordtype_filter ;
	if(($v_recordtype_filter == '007') || ($v_recordtype_filter == '004')){
		@session_start();
		$_SESSION['v_record_id_print'] = $v_record_id;
	}
	$v_receipt_richtext_string = _read_file($v_receipt_richtext_file);
	//echo htmlspecialchars($v_receipt_richtext_string);exit;

//Bo sung in bien nhan dat dai
//	if($v_recordtype_filter=='011'||$v_recordtype_filter=='012'||$v_recordtype_filter=='013'||$v_recordtype_filter=='014'){
		if($arr_single_record_progress_land['NGAY_HEN_KIEM_TRA'] != null){
			$array0 = explode(" " , $arr_single_record_progress_land['NGAY_HEN_KIEM_TRA']);
			$v_receipt_richtext_string = str_replace("#NHKT#",Get_DMY($array0[0]),$v_receipt_richtext_string);
		}	else{	$v_receipt_richtext_string = str_replace("#NHKT#",'',$v_receipt_richtext_string);	}
	
		if($arr_single_record_progress_land['NGAY_NHAN_QDP'] != null){
			$array1 = explode(" " , $arr_single_record_progress_land['NGAY_NHAN_QDP']);
			$v_receipt_richtext_string = str_replace("#NNQDP#",Get_DMY($array1[0]),$v_receipt_richtext_string);
		}	else{	$v_receipt_richtext_string = str_replace("#NNQDP#",'',$v_receipt_richtext_string);	}
	
		if($arr_single_record_progress_land['NGAY_NOP_BLP'] != null){
			$array2 = explode(" " , $arr_single_record_progress_land['NGAY_NOP_BLP']);
			$v_receipt_richtext_string = str_replace("#NNBLP#",Get_DMY($array2[0]),$v_receipt_richtext_string);
		}	else{	$v_receipt_richtext_string = str_replace("#NNBLP#",'',$v_receipt_richtext_string);	}
	
		if($arr_single_record_progress_land['NGAY_HEN_NHAN_TBT'] != null){
			$array3 = explode(" " , $arr_single_record_progress_land['NGAY_HEN_NHAN_TBT']);
			$v_receipt_richtext_string = str_replace("#NHNTBT#",Get_DMY($array3[0]),$v_receipt_richtext_string);
		}	else{	$v_receipt_richtext_string = str_replace("#NHNTBT#",'',$v_receipt_richtext_string);	}
	
		if($arr_single_record_progress_land['NGAY_NHAN_TBT'] != null){
			$array4 = explode(" " , $arr_single_record_progress_land['NGAY_NHAN_TBT']);
			$v_receipt_richtext_string = str_replace("#NNTBT#",Get_DMY($array4[0]),$v_receipt_richtext_string);	
		}	else{	$v_receipt_richtext_string = str_replace("#NNTBT#",'',$v_receipt_richtext_string);	}
	
		if($arr_single_record_progress_land['NGAY_NOP_BLT'] != null){
			$array5 = explode(" " , $arr_single_record_progress_land['NGAY_NOP_BLT']);
			$v_receipt_richtext_string = str_replace("#NNBLT#",Get_DMY($array5[0]),$v_receipt_richtext_string);	
		}	else{	$v_receipt_richtext_string = str_replace("#NNBLT#",'',$v_receipt_richtext_string);	}

		if($arr_single_record_progress_land['NGAY_HEN_TRA_KET_QUA'] != null){
			$array6 = explode(" " , $arr_single_record_progress_land['NGAY_HEN_TRA_KET_QUA']);
			$array6 = split('-',$array6[0]);
			$v_receipt_richtext_string = str_replace("#APPOINTED_DATE#","ng&#224;y ".$array6[2]." th&#225;ng ".$array6[1]." n&#259;m ".$array6[0],$v_receipt_richtext_string);	
		}
		
		if($arr_single_record_progress_land['TL_RTB_PHAT'] != null||$arr_single_record_progress_land['TL_RTB_THUE'] != null)	{
			$v_receipt_richtext_string = str_replace("#RECEIVED_DATE#","ng&#224;y ".date("d")." th&#225;ng ".date("m")." n&#259;m ".date("Y"),$v_receipt_richtext_string);	
			$v_receipt_richtext_string = str_replace("#APPOINTED_DATE#",'',$v_receipt_richtext_string);	
		}
//	}
	//End
	echo $v_richtext_output = Print_Receipt_From_XML($v_receipt_xml_string,$v_receipt_richtext_string,$v_xml_str, $arr_single_record);
}
//In giay bien nhan nhieu ho so cua phong noi vu...
else{
	$v_file_name = "giay_bien_nhan.htm";
	$v_receipt_xml_file = "../../xml/".$v_recordtype_filter."/mau_in_giay_bien_nhan_nhieu_ho_so.xml";
	$v_receipt_richtext_file = "../../template/".$v_recordtype_filter."/mau_giay_bien_nhan_nhieu_ho_so.htm";
	if (!file_exists($v_receipt_richtext_file)){
		$v_receipt_richtext_file = "../../template/mau_giay_bien_nhan_nhieu_ho_so.htm";
	}
	if (file_exists($v_receipt_xml_file)){
		$v_receipt_xml_string = _read_file($v_receipt_xml_file);
	}else{
		$v_receipt_xml_file = "../../xml/other/mau_in_giay_bien_nhan_nhieu_ho_so.xml";
		$v_receipt_xml_string = _read_file($v_receipt_xml_file);
	}
	
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_receipt_xml_string);
	$table_struct_rax->record_delim = 'str_sql';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord();
	$table_struct_row = $table_struct_rec->getRow();
	$str_sql = $table_struct_row["sql"];
	$str_sql_replace = $table_struct_row["str_sql_replace"];
	//echo $str_sql; exit;
		
	//DatCQ: Bo sung de in giay bien nhan theo danh sach ho so
	$v_record_id = '';
	for($i=0;$i<sizeof($v_record_id_list);$i++)
		$v_record_id = $v_record_id . $v_record_id_list[$i] . ',';
	//End: Bo sung de in giay bien nhan theo danh sach ho so
	
	$str_sql = str_replace("#".$str_sql_replace."#",$v_record_id,$str_sql);

//	echo $str_sql; exit;
	//In bang danh sach ho so cho chuc nang in bien nhan nhieu ho so
	$v_file_list = "danh_sach_ho_so_bien_nhan.xml";
	//file dinh dang bang hien thi danh sach ho so da tiep nhan
	$v_table_struct_xml_file = "../../xml/".$v_recordtype_filter."/".$v_file_list;
	if (file_exists($v_table_struct_xml_file)){
		$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
	}else{
		$v_table_struct_xml_file = "../../xml/other/".$v_file_list;
		$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
	}	
	
	$table_struct_rax_1 = new RAX(); 
	$table_struct_rec_1 = new RAX(); 
	$table_struct_rax_1 ->open($v_table_struct_xml_string);
	$table_struct_rax_1 ->record_delim = 'col';
	$table_struct_rax_1 ->parse();
	$table_struct_rec_1 = $table_struct_rax_1->readRecord(); 

	//Bat dau cong xau html de in tieu de cua bang danh sach du lieu
	$v_html_string = '';
	$v_html_string = $v_html_string  . '<form action="index.php" method="post" name="f_dsp_all_record">';
	$v_html_string = $v_html_string  . '<table class="list_table3" width="100%" cellpadding="0" cellspacing="0">';
	$v_html_temp_width = '';
	$v_html_temp_label = '';
	$v_column = 0;
	
	while ($table_struct_rec_1) { 
		$table_struct_row_1 = $table_struct_rec_1->getRow();
		$v_label_1 = $table_struct_row_1["label"];
		$v_width_1 = $table_struct_row_1["width"];
		$v_html_temp_width = $v_html_temp_width  . '<col width="'.$v_width_1.'">';
		$v_html_temp_label = $v_html_temp_label . '<td align="center">'.$v_label_1.'</td>';
		$table_struct_rec_1 = $table_struct_rax_1->readRecord();
		$v_column_1 ++;
	}

	$v_html_string = $v_html_string  . $v_html_temp_width;
	$v_html_string = $v_html_string  . '<tr class="header2">';
	$v_html_string = $v_html_string  . $v_html_temp_label;
	$v_html_string = $v_html_string  . '</tr></table>';

	//Bat dau xau in danh sach tung dong du lieu
	$v_html_string = $v_html_string  . '<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">';
	$v_html_string = $v_html_string  . $v_html_temp_width;
	$arr_all_record = Query_Data_For_Colunm_name($str_sql);
	$v_count = sizeof($arr_all_record);

//	echo '12321321 '.$v_count; exit; 
	if ($v_count >0){
		for($row_index = 0;$row_index< $v_count ;$row_index++){
			$v_url = "";
			$v_received_record_xml_data = $arr_all_record[$row_index]['C_RECEIVED_RECORD_XML_DATA'];
			if ($v_current_style_name == "odd_row"){
				$v_current_style_name = "round_row";
			}else{
				$v_current_style_name = "odd_row";
			}
			$v_html_string = $v_html_string  .'<tr class="'.$v_current_style_name.'" >'; 

			$table_struct_rax_1 = new RAX(); 
			$table_struct_rec_1 = new RAX(); 
			$table_struct_rax_1 ->open($v_table_struct_xml_string);
			$table_struct_rax_1 ->record_delim = 'col';
			$table_struct_rax_1 ->parse();
			$table_struct_rec_1  = $table_struct_rax_1 ->readRecord(); 
			
			while ($table_struct_rec_1) { 
				$table_struct_row_1 = $table_struct_rec_1->getRow();
				$v_type = $table_struct_row_1["type"];
				$v_width = $table_struct_row_1["width"];
				$v_align = $table_struct_row_1["align"];
				$v_xml_data = $table_struct_row_1["xml_data"];
				$v_column_name = $table_struct_row_1["column_name"];
				$v_xml_tag_in_db = $table_struct_row_1["xml_tag_in_db"];
				$v_php_function = $table_struct_row_1["php_function"];
				$v_selectbox_option_sql = $table_struct_row_1["selectbox_option_sql"];
				
				if ($v_xml_data=="true"){
					$column_rax = new RAX(); 
					$column_rec = new RAX();
					$column_rax->open($v_received_record_xml_data);
					$column_rax->record_delim = 'data_list';
					$column_rax->parse();
					$column_rec = $column_rax->readRecord(); 
					$column_row = $column_rec->getRow();
					$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]);
					$v_html_string = $v_html_string  . Element_Type($v_type); 
				}else{
					$v_value = $arr_all_record[$row_index][$v_column_name];
					if ($v_type=="checkbox"){
						$v_value_id = $arr_all_record[$row_index][$v_column_name];
						$v_url = "row_onclick(" . "document.forms(0).hdn_record_id"  . "," . $v_value_id . "," . "'".		$v_fuseaction_onclick."','" . $v_goto_url . "')";
					}
					$v_html_string = $v_html_string  . Element_Type($v_type); 
				}
				$table_struct_rec_1 = $table_struct_rax_1->readRecord();
			} //End while
		$v_html_string = $v_html_string  .'</tr>';
		}	//End for
	}	//End if

	if ($v_current_style_name == "odd_row"){
		$v_next_style_name = "round_row";
	}else{
		$v_next_style_name = "odd_row";
	}

	$v_html_string = $v_html_string  . _add_empty_row($v_count,_CONST_NUMBER_OF_ROW_PER_LIST,$v_current_style_name,	$v_next_style_name,$v_column);
	$v_html_string = $v_html_string  .'</table>';

	// Dua danh sach bang thay the cho #DANH_SACH_HO_SO#
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$v_arr= $ado_conn->GetRow($str_sql); 
	$v_receipt_richtext_file = "../../template/".$v_recordtype_filter."/mau_giay_bien_nhan_nhieu_ho_so.htm";
	$v_file_name = "mau_giay_bien_nhan_nhieu_ho_so.htm";
	$v_xml_str = $v_arr['C_RECEIVED_RECORD_XML_DATA'];

	$v_record_id	= intval($v_record_id);
	$sql = "Exec Onegate_RecordGetSingle " . $v_record_id;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$arr_single_record = $ado_conn->GetRow($sql); 
	$arr_single_record[C_RECORDTYPE_NAME] = stripslashes($arr_single_record[C_RECORDTYPE_NAME]);
	$v_recordtype = $arr_single_record['C_RECORDTYPE_NAME'];
	
	if ($v_xml_str ==''){
		$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
	}
	
	$count_record = sizeof($v_record_id_list);
	
	$v_receipt_richtext_string = _read_file($v_receipt_richtext_file);
	$v_receipt_richtext_string = str_replace("#DANH_SACH_HO_SO#",$v_html_string,$v_receipt_richtext_string);
	$v_receipt_richtext_string = str_replace("#NAME_STAFF#",$name_staff_receipt,$v_receipt_richtext_string);
	$v_receipt_richtext_string = str_replace("#ADDRESS_STAFF#",$address_staff_receipt,$v_receipt_richtext_string);
	$v_receipt_richtext_string = str_replace("#RECORDTYPE#",$v_recordtype,$v_receipt_richtext_string);
	$v_receipt_richtext_string = str_replace("#DATE_RECEIPT#",$date_receipt,$v_receipt_richtext_string);
	$v_receipt_richtext_string = str_replace("#SO_LUONG_HO_SO#",$count_record. " h&#7891; s&#417;.",$v_receipt_richtext_string);
	echo $v_richtext_output = Print_Receipt_From_XML($v_receipt_xml_string,$v_receipt_richtext_string,$v_xml_str,$v_arr);
}

?>
<!--<script language="javascript">
	window.location = "<?php echo $v_file_name;?>";
</script>-->